package com.huawei.esdk.oa.device.ad;

import org.apache.log4j.Logger;
import com.huawei.esdk.platform.common.utils.ApplicationContextUtil;
import com.huawei.esdk.platform.nemgr.base.MultiConnDeviceBase;
import com.huawei.esdk.platform.nemgr.itf.IDeviceConnection;
import com.huawei.esdk.platform.nemgr.itf.IDeviceManager;
import com.huawei.esdk.tp.device.oa.IADCapability;

public class ADDevice extends MultiConnDeviceBase {
	
	private static final Logger LOGGER = Logger
			.getLogger(ADDevice.class);
	
    private IDeviceManager deviceManager = ApplicationContextUtil
            .getBean("deviceManager");
	
    private String sap;
    
	public ADDevice(String sap) {
        this.sap = sap;
        prepareDeviceCapability(sap);
	}
	
	private void prepareDeviceCapability(String sap)
	{
        LOGGER.debug("The SAP = " + sap);
        addServiceObjectMap(IADCapability.class, new ADCapability());
	}

	@Override
	public IDeviceConnection createConnection(String connId, String sap,
			String loginUser, String loginPwd) {
		return new ADConnection(this, sap, loginUser, loginPwd);
	}

	@Override
	public String getConnIdFromContext() {
		return "";
	}

	@Override
	public Boolean releaseConns() {
        for (String key : id2Connection.keySet())
        {
            IDeviceConnection conn = id2Connection.get(key);
            deviceManager.releaseConn(conn);
        }
        return true;
	}

	public String getSap() {
		return sap;
	}

	public void setSap(String sap) {
		this.sap = sap;
	}
	
}